class Solution {//leetcode529——扫雷游戏
private:
    int dx[9]={-1,0,1,-1,1,-1,0,1};
    int dy[9]={-1,-1,-1,0,0,1,1,1};
void dfs(vector<vector<char>>& board,int i,int j){
    if(board[i][j]=='M') {
        board[i][j]='X';
        return;
    }
    else {
        int cnt=0;
        for(int k=0;k<8;k++){
            int x=j+dx[k];
            int y=i+dy[k];
            if(x>=0&&x<n&&y>=0&&y<m&&board[y][x]=='M') cnt++;
        }
        if(cnt!=0){
            board[i][j]=cnt+'0';
            return;
        }
        //cnt==0
        board[i][j]='B';
        for(int k=0;k<8;k++){
            int x=j+dx[k];
            int y=i+dy[k];
            if(x>=0&&x<n&&y>=0&&y<m&&board[y][x]=='E') dfs(board,y,x);
        }
    }
}
public:
    vector<vector<char>> updateBoard(vector<vector<char>>& board, vector<int>& click) {
        m=board.size(),n=board[0].size();
        dfs(board,click[0],click[1]);
        return board;
    }
private:
    int m;
    int n;
};